<template>
	<el-container>
		<el-aside width="200px" v-loading="showGrouploading">
			<el-container>
				<el-header>
					<el-input placeholder="输入关键字进行过滤" v-model="groupFilterText" clearable></el-input>
				</el-header>
				<el-main class="nopadding">
					<el-tree ref="group" class="menu" node-key="deptId" :data="group" :props="groupsProps" :current-node-key="''" :highlight-current="true" :expand-on-click-node="false" :filter-node-method="groupFilterNode" @node-click="groupClick"></el-tree>
				</el-main>
			</el-container>
		</el-aside>
		<el-container>
			<el-header>
				<div class="left-panel">
				</div>
				<div class="right-panel">
					<div class="right-panel-search">
						<el-input v-model="search.keyword" placeholder="姓名 / 工号 / 身份证号" clearable></el-input>
						<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
					</div>
				</div>
			</el-header>
			<el-main class="nopadding">
				<scTable ref="table" :apiObj="apiObj" stripe remoteSort remoteFilter @row-click="searchUserInfoList">
					<el-table-column label="#" type="index" width="50"></el-table-column>
					<el-table-column label="头像" width="80">
						<template #default="scope">
							<el-avatar :src="scope.row.avatar" size="small" style="display: flex;"></el-avatar>
						</template>
					</el-table-column>
					<el-table-column label="姓名" prop="userName" width="100"></el-table-column>
					<el-table-column label="性别" prop="sex" width="60">
						<template #default="scope">
							<el-button type="primary" size="small" v-if="scope.row.sex==='1'">男</el-button>
							<el-button type="danger" size="small" v-else-if="scope.row.sex==='0'">女</el-button>
							<el-button type="info" size="small" v-else>保密</el-button>
						</template>
					</el-table-column>
					<el-table-column label="所在部门" prop="deptName" width="100"></el-table-column>
					<el-table-column label="入职时间" prop="employedTime" width="100"></el-table-column>
					<el-table-column label="工种" prop="workTypeName" width="100"></el-table-column>
					<el-table-column label="联系电话" prop="phone" width="150"></el-table-column>
					<el-table-column label="操作" fixed="right" align="right" width="100">
						<template #default="scope">
							<el-button-group>
								<el-button text type="primary" size="small" @click="table_add(scope.row, scope.$index)">评价</el-button>
							</el-button-group>
						</template>
					</el-table-column>
				</scTable>
			</el-main>
		</el-container>
		<el-aside width="40%">
			<el-container>
				<el-header>
				<div class="left-panel">
					<el-button type="danger" plain icon="el-icon-delete" :disabled="selection.length==0" @click="batch_del"></el-button>
				</div>
				</el-header>
				<el-main class="nopadding">
					<scTable ref="table1" :apiObj="apiObj1" @selection-change="selectionChange" stripe remoteSort remoteFilter>
						<el-table-column type="selection" width="50"></el-table-column>
						<el-table-column label="#" type="index" width="50"></el-table-column>
						<el-table-column label="姓名" prop="userName" width="100"></el-table-column>
						<el-table-column label="工作态度" prop="attitudeLevel" width="80">
							<template #default="scope">
								{{scope.row.attitudeLevel}}/分
							</template>
						</el-table-column>
						<el-table-column label="学习能力" prop="learnLevel" width="80">
							<template #default="scope">
								{{scope.row.learnLevel}}/分
							</template>
						</el-table-column>
						<el-table-column label="工作持能" prop="skillLevel" width="80">
							<template #default="scope">
								{{scope.row.skillLevel}}/分
							</template>
						</el-table-column>
						<el-table-column label="操作" fixed="right" align="right" width="170">
							<template #default="scope">
								<el-button-group>
									<el-button text type="primary" size="small" @click="table_show(scope.row, scope.$index)">查看</el-button>
									<el-button text type="primary" size="small" @click="table_edit(scope.row, scope.$index)">编辑</el-button>
									<el-popconfirm title="确定删除吗？" @confirm="table_del(scope.row, scope.$index)">
										<template #reference>
											<el-button text type="primary" size="small">删除</el-button>
										</template>
									</el-popconfirm>
								</el-button-group>
							</template>
						</el-table-column>
					</scTable>
				</el-main>
			</el-container>
		</el-aside>
	</el-container>
	<save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save=false"></save-dialog>
	<recordDetails v-if="dialog.detailsSave" ref="detailsDialog" @closed="dialog.detailsSave=false"></recordDetails>
</template>

<script>
import saveDialog from './save'
import recordDetails from '@/views/hr/evaluate/search/details'
export default {
	name: 'Hr Evaluate Create',
	components: {
		saveDialog,
		recordDetails
	},
	data() {
		return {
			dialog: {
				save: false,
				detailsSave:false
			},
			selection: [],
			showGrouploading: false,
			groupFilterText: '',
			group: [],
			groupsProps: {
				label:"deptName",
				value: "deptId"
			},
			apiObj1:this.$API.hr.hrEvaluate.getHrEvaluateByUserIdList,
			apiObj: this.$API.hr.hrUser.getHrUserListByDeptId,
			search: {
				keyword: null
			},
			search1: {
				userId:'',
			}
		}
	},
	watch: {
		groupFilterText(val) {
			this.$refs.group.filter(val);
		}
	},
	mounted() {
		this.getDeptGroup()
	},
	methods: {
		searchUserInfoList(row)
		{
			this.search1.userId = row.userId;
			this.$refs.table1.upData(this.search1)
		},
		//表格选择后回调事件
		selectionChange(selection) {
			this.selection = selection;
		},
		//编辑
		table_add(row){
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('add').setData(row)
			})
		},
		table_edit(row){
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('edit').setData(row)
			})
		},
		//查看
		table_show(row){
			this.dialog.detailsSave = true
			this.$nextTick(() => {
				this.$refs.detailsDialog.open().setData(row)
			})
		},
		//加载树数据
		async getDeptGroup(){
			this.showGrouploading = true;
			var res = await this.$API.hr.hrDepartment.getHrDepartmentTree.get();
			this.showGrouploading = false;
			var allNode ={deptId: '', deptName: '所有'}
			res.data.unshift(allNode);
			this.group = res.data;
		},
		//树过滤
		groupFilterNode(value, data){
			if (!value) return true;
			return data.deptName.indexOf(value) !== -1;
		},
		//树点击事件
		groupClick(data){
			var params = {
				deptId: data.deptId
			}
			this.$refs.table.reload(params)
		},
		//搜索
		upsearch(){
			this.$refs.table.upData(this.search)
		},
		//本地更新数据
		handleSuccess(data, mode){
			this.$refs.table1.refresh()
		},
		//删除
		async table_del(row) {
			var reqData = {recordId: row.recordId}
			var res = await this.$API.hr.hrEvaluate.deleteHrEvaluate.post(reqData);
			if (res.code == 200) {
				this.$refs.table1.refresh()
				this.$message.success("删除成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//批量删除
		async batch_del() {
			await this.$confirm(`确定删除选中的 ${this.selection.length} 项吗？`, '提示', {
				type: 'warning'
			}).then(async () => {
				var recordIdArr = [];
				for (var i = 0; i < this.selection.length; i++) {
					recordIdArr.push(this.selection[i].recordId);
				}
				const loading = this.$loading();
				var res = await this.$API.hr.hrEvaluate.deleteHrEvaluateByIds.post({ids:recordIdArr});
				if (res.code == 200) {
					this.$refs.table1.refresh()
					this.$message.success(res.message)
				} else {
					this.$alert(res.message, "提示", {type: 'error'})
				}
				loading.close();
			}).catch(() => {

			})
		},
	}
}
</script>

<style>
</style>
